<template>
  <div class="folder-explorer">
    <div class="folder-header">
      <div class="current-path">
        <el-icon><Folder /></el-icon>
        <span class="path-text">{{ dirPath || '根目录' }}</span>
        
      </div>
      <el-button 
        class="back-button" 
        type="primary" 
        size="small" 
        @click="emit('back')"
        :disabled="!dirPath"
        plain
      >
        <el-icon><Back /></el-icon> 返回上级
      </el-button>
    </div>
    
    <div class="folder-content">
      <div v-if="folderList && Array.isArray(folderList) && folderList.length > 0" class="folder-list">
        <div 
          v-for="(item, index) in folderList" 
          :key="index" 
          class="folder-item"
          @click="emit('chose-folder', item)"
        >
          <el-icon class="folder-icon"><FolderOpened /></el-icon>
          <span class="folder-name">{{ item }}</span>
        </div>
      </div>
      <div v-else class="empty-folder">
        <el-empty description="暂无文件夹" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Folder, Back, FolderOpened } from '@element-plus/icons-vue'

const dirPath = defineModel<string>('dirPath')
const folderList = defineModel<string[]>('folderList')

const emit = defineEmits(['chose-folder', 'back'])
</script>

<style scoped lang="scss">
.folder-explorer {
  font-family: 'PingFang SC', Arial, sans-serif;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.folder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e7eb 100%);
  border-bottom: 1px solid #ebeef5;
}

.current-path {
  display: flex;
  align-items: center;
  flex: 1;
  overflow: hidden;
  color: #606266;
  
  .el-icon {
    margin-right: 8px;
    color: #409eff;
    font-size: 18px;
  }
  
  .path-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    font-weight: 500;
  }
}

.back-button {
  margin-left: 16px;
  
  .el-icon {
    margin-right: 4px;
  }
  
  &:hover {
    transform: translateX(-2px);
  }
}

.folder-content {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
  background-color: #fafafa;
}

.folder-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.folder-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background-color: #fff;
  border-radius: 6px;
  border: 1px solid #ebeef5;
  cursor: pointer;
  transition: all 0.25s ease;
  
  &:hover {
    background-color: #f0f7ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: #c6e2ff;
  }
  
  .folder-icon {
    color: #e6a23c;
    font-size: 20px;
    margin-right: 10px;
  }
  
  .folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #303133;
    font-size: 14px;
  }
}

.empty-folder {
  padding: 40px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

@media (max-width: 768px) {
  .folder-list {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
  
  .folder-header {
    padding: 10px 16px;
  }
  
  .folder-item {
    padding: 8px 12px;
  }
}
</style>  
